const vscode = require('vscode');
const { Configs } = require('./Configs');
const path = require('path')

const configs = new Configs()
const root = path.resolve(configs.rootPath).replace(/\\/g, "\\\\")

class FileNameNoteDecoration extends vscode.FileDecoration {

    /**
     * 
     * @param {string} badge 
     * @param {string} tooltip 
     * @param {RegExp[]} rules 
     */
    constructor(badge, tooltip, rules) {
        super(badge, tooltip);
        this.rules = rules
    }

    /**
     * 
     * @param {vscode.Uri} uri 
     * @param {vscode.CancellationToken} token 
     */
    some(uri, token) {
        if (this.rules.some(rule => new RegExp(`${root}\\\\${rule.source}`, "i").test(uri.fsPath))) {
            return this
        }
    }
}

const fileNotes = [
    // 💻 一、服务器目录（Mir200/）
    new FileNameNoteDecoration("数据库网关💻", "负责连接和管理游戏数据库", [/DBServer$/i]),
    new FileNameNoteDecoration("登录网关💻", "处理玩家登录请求，验证账号密码，转发至登录服务器。", [/LoginGate$/i]),
    new FileNameNoteDecoration("登录服务端💻", "实际处理玩家登录逻辑，维护在线用户列表。", [/LoginSrv$/i]),
    new FileNameNoteDecoration("核心服务端💻", "游戏主服务，处理战斗、地图、任务、NPC 等核心逻辑。", [/Mir200$/i]),
    new FileNameNoteDecoration("运行网关💻", "处理玩家进入游戏后的数据通信。", [/RunGate$/i]),
    new FileNameNoteDecoration("角色网关💻", "角色选择界面网关，处理角色创建、删除、选服等操作。", [/SelGate$/i]),
    new FileNameNoteDecoration("日志网关💻", "记录游戏运行日志，便于后期分析。", [/LogServer$/i]),
    // 🧱 一、核心配置文件（Mir200/）
    new FileNameNoteDecoration("运行地址🧱", "指定服务器运行地址或端口信息", [/Mir200\\!runaddr.txt$/i]),
    new FileNameNoteDecoration("封禁名单🧱", "可能用于记录滥用行为或封禁名单", [/Mir200\\!abuse.txt$/i]),
    new FileNameNoteDecoration("基础设置🧱", "服务器启动时加载的基础设置文件", [/Mir200\\!setup.txt$/i]),
    new FileNameNoteDecoration("连接配置表🧱", "服务器列表或连接配置表", [/Mir200\\!servertable.txt$/i]),
    new FileNameNoteDecoration("全局变量配置🧱", "全局变量配置文件，如经验倍率、掉率调整等", [/Mir200\\GlobalVal.ini$/i]),
    new FileNameNoteDecoration("经验值配置🧱", "经验值配置文件，定义各等级所需经验值", [/Mir200\\Exps.ini$/i]),
    new FileNameNoteDecoration("命令配置🧱", "命令配置文件，定义 GM 指令权限和功能", [/Mir200\\Command.ini$/i]),
    new FileNameNoteDecoration("玩家属性配置🧱", "玩家基础属性配置，如初始攻击力、防御力等", [/Mir200\\BaseAbil.ini$/i]),
    new FileNameNoteDecoration("字符串资源🧱", "游戏内字符串资源，用于多语言支持", [/Mir200\\String.ini$/i]),
    new FileNameNoteDecoration("短信通知配置🧱", "短信通知相关配置，如充值提醒", [/Mir200\\SendSMS.ini$/i]),
    new FileNameNoteDecoration("数据存储目录🧱", "存放游戏运行过程中产生的临时或持久化数据。", [/Mud2$/i]),
    new FileNameNoteDecoration("环境配置目录🧱", "存放各种配置文件，决定游戏行为。", [/Mir200\\Envir$/i]),
    // 🗺️ 二、地图与事件配置（Envir/）
    new FileNameNoteDecoration("地图信息🗺️", "编号、名称、出生点、是否允许PK", [/Mir200\\Envir\\MapInfo.txt$/i]),
    new FileNameNoteDecoration("小地图信息🗺️", "小地图坐标偏移配置，客户端显示缩略图使用", [/Mir200\\Envir\\MiniMap.txt$/i]),
    new FileNameNoteDecoration("地图任务触发🗺️", "地图任务触发点配置", [/Mir200\\Envir\\MapQuest.txt$/i]),
    new FileNameNoteDecoration("地图事件🗺️", "地图事件脚本绑定，如节日活动、定时刷怪", [/Mir200\\Envir\\MapEvent.txt$/i]),
    new FileNameNoteDecoration("出生点配置🗺️", "角色创建后的默认出生点配置", [/Mir200\\Envir\\StartPoint.txt$/i]),
    new FileNameNoteDecoration("怪物刷新点🗺️", "怪物刷新点配置，定义怪物在地图上的分布位置", [/Mir200\\Envir\\MonGen.txt$/i]),
    new FileNameNoteDecoration("怪物对话🗺️", "怪物对话文本，用于特定怪物喊话（如 BOSS 出现）", [/Mir200\\Envir\\MonSayMsg.txt$/i]),
    // 💀 三、怪物与掉落配置
    new FileNameNoteDecoration("怪物掉落配置💀", "定义怪物爆率", [/Mir200\\Envir\\MonItems$/i]),
    new FileNameNoteDecoration("稀有物品限制💀", "控制某些稀有物品的最大掉落次数，防止刷装备", [/Mir200\\Envir\\MonDropLimitList.txt$/i]),
    new FileNameNoteDecoration("怪物特殊能力💀", "怪物特殊能力配置，如技能、攻击方式等", [/Mir200\\Envir\\MonSpAbilList.txt$/i]),
    // 🛡️ 四、物品系统配置
    new FileNameNoteDecoration("物品描述🛡️", "物品描述信息，用于客户端显示", [/Mir200\\Envir\\ItemDescList.txt$/i]),
    new FileNameNoteDecoration("高级物品描述🛡️", "高级物品描述优先级控制", [/Mir200\\Envir\\ItemDescTopList.txt$/i]),
    new FileNameNoteDecoration("物品名称映射🛡️", "物品名称映射表", [/Mir200\\Envir\\ItemNameList.txt$/i]),
    new FileNameNoteDecoration("特殊物品描述补充🛡️", "特殊物品描述补充", [/Mir200\\Envir\\TzItemDescList.txt$/i]),
    new FileNameNoteDecoration("商店出售物品🛡️", "商店出售物品列表", [/Mir200\\Envir\\ShopItemList.txt$/i]),
    new FileNameNoteDecoration("复活道具🛡️", "复活道具列表", [/Mir200\\Envir\\RevivalItemList.txt$/i]),
    new FileNameNoteDecoration("效果类物品🛡️", "效果类物品配置（如药水、卷轴）", [/Mir200\\Envir\\EffectItemList.txt$/i]),
    new FileNameNoteDecoration("加强技能物品🛡️", "加强技能效果的物品", [/Mir200\\Envir\\SkillPowerItemList.txt$/i]),
    new FileNameNoteDecoration("物品组合配置🛡️", "物品组合配置，如套装效果", [/Mir200\\Envir\\GroupItemList.txt$/i]),
    new FileNameNoteDecoration("物品日志🛡️", "需要记录日志的物品名列表", [/Mir200\\Envir\\GameLogItemNameList.txt$/i]),
    new FileNameNoteDecoration("物品生成规则🛡️", "新物品生成规则", [/Mir200\\Envir\\NewItemFromList.txt$/i]),
    new FileNameNoteDecoration("记忆物品列表🛡️", "记忆物品列表（如玩家拥有后解锁新内容）", [/Mir200\\Envir\\RememberItemList.txt$/i]),
    new FileNameNoteDecoration("装备合成🛡️", "管理装备合成或铸造系统‌", [/Mir200\\Envir\\FoundryList.txt$/i]),
    // 🧙‍♂️ 五、NPC 与任务系统
    new FileNameNoteDecoration("NPC脚本目录🧙‍♂️", "NPC脚本文件目录", [/Mir200\\Envir\\Market_Def$/i]),
    new FileNameNoteDecoration("NPC列表🧙‍♂️", "NPC 列表及其行为配置", [/Mir200\\Envir\\Npcs.txt$/i]),
    new FileNameNoteDecoration("PC行为🧙‍♂️", "NPC 行为定义文件，包含对话逻辑", [/Mir200\\Envir\\Npc_Def\\.+?\.def$/i]),
    new FileNameNoteDecoration("NPC数据🧙‍♂️", "NPC 数据文件，可能包含商店信息、任务奖励等", [/Mir200\\Envir\\Npc_Data\\.+?\.dat$/i]),
    new FileNameNoteDecoration("Lua🧙‍♂️", "使用 Lua 编写的任务脚本，处理复杂交互逻辑", [/Mir200\\Envir\\QuestDiary\\.+?\.lua$/i]),
    new FileNameNoteDecoration("地图任务🧙‍♂️", "地图任务定义文件", [/Mir200\\Envir\\MapQuest_Def\\.+?\.def$/i]),
    // 🔐 六、安全与限制配置
    new FileNameNoteDecoration("禁用账号🔐", "被禁止登录的账号列表", [/Mir200\\Envir\\DenyAccountList.txt$/i]),
    new FileNameNoteDecoration("禁用角色🔐", "禁止使用的角色名", [/Mir200\\Envir\\DenyChrNameList.txt$/i]),
    new FileNameNoteDecoration("IP黑名单🔐", "IP 地址黑名单", [/Mir200\\Envir\\DenyIPAddrList.txt$/i]),
    new FileNameNoteDecoration("设备黑名单🔐", "设备 ID 黑名单", [/Mir200\\Envir\\DenyMachineIDList.txt$/i]),
    new FileNameNoteDecoration("禁止合成物品🔐", "禁止合成的物品列表", [/Mir200\\Envir\\DisableMakeItem.txt$/i]),
    new FileNameNoteDecoration("背包丢弃🔐", "不允许丢弃到背包的物品", [/Mir200\\Envir\\DisableDropToBagItem.txt$/i]),
    new FileNameNoteDecoration("退出不使用的物品🔐", "禁止退出时不使用的物品", [/Mir200\\Envir\\DisableExitNoUseItem.txt$/i]),
    new FileNameNoteDecoration("禁止传送地图🔐", "禁止传送的地图列表", [/Mir200\\Envir\\DisableMoveMap.txt$/i]),
    new FileNameNoteDecoration("禁脱装备🔐", "禁止脱下的装备", [/Mir200\\Envir\\DisableTakeOffList.txt$/i]),
    new FileNameNoteDecoration("隐藏物品🔐", "隐藏部分物品", [/Mir200\\Envir\\DisableShowItemFromList.txt$/i]),
    new FileNameNoteDecoration("合成物品🔐", "允许合成的物品列表", [/Mir200\\Envir\\EnableMakeItem.txt$/i]),
    new FileNameNoteDecoration("允许拾取物品🔐", "允许拾取的物品列表", [/Mir200\\Envir\\EnablePickUpItem.txt$/i]),
    new FileNameNoteDecoration("优先拾取物品🔐", "优先拾取的物品列表", [/Mir200\\Envir\\PriorityPickUpItem.txt$/i]),
    new FileNameNoteDecoration("冻结状态物品🔐", "冻结状态物品配置", [/Mir200\\Envir\\FrozenItemList.txt$/i]),
    // 🧬 七、战斗与技能系统
    new FileNameNoteDecoration("技能冷却时间🧬", "技能列表及冷却时间配置", [/Mir200\\Envir\\MagicListAC.ini$/i]),
    new FileNameNoteDecoration("魔法护盾物品🧬", "魔法护盾物品配置", [/Mir200\\Envir\\MagicShieldItemList.txt$/i]),
    new FileNameNoteDecoration("麻痹类物品🧬", "麻痹类物品配置", [/Mir200\\Envir\\MDParalysisItemList.txt$/i]),
    new FileNameNoteDecoration("麻痹类物品🧬", "同上，可能是不同版本配置", [/Mir200\\Envir\\ParalysisItemList.txt$/i]),
    new FileNameNoteDecoration("缠绕类技能物品🧬", "缠绕类技能物品配置", [/Mir200\\Envir\\CobwebWindingItemList.txt$/i]),
    new FileNameNoteDecoration("特效图片资源🧬", "特效图片资源引用", [/Mir200\\Envir\\EffectImageList.txt$/i]),
    new FileNameNoteDecoration("特效背景物品🧬", "特效背景提示物品", [/Mir200\\Envir\\EffectHintBGItems.txt$/i]),
    new FileNameNoteDecoration("悬浮框背景特效🧬", "悬浮框背景特效", [/Mir200\\Envir\\EffectHintBG.txt$/i]),
    // 🧭 八、其他辅助配置
    new FileNameNoteDecoration("", "Access🧭 数据库文件，可能存储通用数据", [/Mir200\\Envir\\Data.mdb$/i]),
    new FileNameNoteDecoration("自动加载离线🧭", "自动加载离线玩家数据", [/Mir200\\Envir\\AutoLoadOffline.txt$/i]),
    new FileNameNoteDecoration("机器人配置🧭", "机器人配置文件，用于测试或挂机", [/Mir200\\Envir\\Robot.txt$/i]),
    new FileNameNoteDecoration("食用物品🧭", "客户端可食用物品列表", [/Mir200\\Envir\\ClientEatItemNameList.txt$/i]),
    new FileNameNoteDecoration("过滤字符🧭", "输入框过滤字符列表", [/Mir200\\Envir\\InputBoxFilterList.txt$/i]),
    new FileNameNoteDecoration("自定义命令🧭", "用户自定义命令配置", [/Mir200\\Envir\\UserCmd.txt$/i]),
    new FileNameNoteDecoration("解除师徒关系🧭", "解除师徒关系配置", [/Mir200\\Envir\\UnMaster.txt$/i]),
    new FileNameNoteDecoration("强制解除师徒关系🧭", "强制解除师徒关系配置", [/Mir200\\Envir\\UnForceMaster.txt$/i]),
    new FileNameNoteDecoration("物品解包🧭", "客户端自动解包配置", [/Mir200\\Envir\\UnbindList.txt$/i]),
    new FileNameNoteDecoration("行会目录🧭", "行会相关配置目录", [/Mir200\\GuildBase$/i]),
    new FileNameNoteDecoration("机器人🧭", "机器人行为定义目录", [/Mir200\\Envir\\Robot_def$/i]),
    new FileNameNoteDecoration("宝箱配置🧭", "宝箱配置文件", [/Mir200\\Envir\\Boxs$/i]),
    new FileNameNoteDecoration("禁止拾取🧭", "禁止范围拾取的物品", [/Mir200\\Envir\\DisableRangePickItem.txt$/i]),
    new FileNameNoteDecoration("守卫拾取🧭", "移动守卫拾取物品规则", [/Mir200\\Envir\\MoveGuardPickItem.txt$/i]),
    new FileNameNoteDecoration("怪物禁止🧭", "禁止怪物移动至指定位置", [/Mir200\\Envir\\MoveMapMonToPosDisable.txt$/i]),
    new FileNameNoteDecoration("不清除的怪物🧭", "不清除的怪物列表", [/Mir200\\Envir\\NoClearMonList.txt$/i]),
    new FileNameNoteDecoration("光柱特效🧭", "光柱特效配置", [/Mir200\\Envir\\PillarOfLightEffect.txt$/i]),
    new FileNameNoteDecoration("光柱特效关联🧭", "光柱特效关联物品列表", [/Mir200\\Envir\\PillarOfLightEffectItemList.txt$/i]),
    new FileNameNoteDecoration("游戏公告🧭", "启动时显示在客户端", [/Mir200\\Notice$/i]),
    new FileNameNoteDecoration("城堡配置🧭", "城堡相关配置，如攻城时间、守卫等", [/Mir200\\Castle$/i]),
    // ⚙️ 九、服务器全局配置（MirServer/）
    new FileNameNoteDecoration("主配置⚙️", "主配置文件，定义引擎路径、数据库连接等", [/Config.ini$/i]),
    new FileNameNoteDecoration("测试环境配置⚙️", "测试环境配置文件", [/ConfigTest.ini$/i]),
    new FileNameNoteDecoration("备份列表⚙️", "备份列表或回滚配置", [/BackList.txt$/i]),
    new FileNameNoteDecoration("工具配置⚙️", "MirEdit 工具配置文件", [/mireditConfig.json$/i]),
    new FileNameNoteDecoration("变量配置⚙️", "/变量配置与描述文件，常用于脚本中动态变量", [/var.json$/i]),
]




/**
 * @implements {vscode.FileDecorationProvider}
 */
class FileNameNotesDecorationProvider {
    /**
     * 
     * @param {vscode.Uri} uri 
     * @param {vscode.CancellationToken} token 
     * @returns 
     */
    provideFileDecoration(uri, token) {
        return fileNotes.find(item => item.some(uri, token));
    }

    /**
     * 
     * @param {vscode.ExtensionContext} context 
     */
    static init(context) {
        const provider = new FileNameNotesDecorationProvider();
        context.subscriptions.push(
            vscode.window.registerFileDecorationProvider(provider),
        );
    }
}



module.exports = { FileNameNotesDecorationProvider };